package model.posterminal;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter(value = "posterminalProducerConverter")
public class PosterminalProducerConverter implements Converter{

	private static final PosterminalProducerDAO prodDAO = new PosterminalProducerDAO();
	
	@Override
	public Object getAsObject(FacesContext facesContext, UIComponent uIComponent, String value) {
		// TODO Auto-generated method stub
		try {
			return prodDAO.find(Long.parseLong(value));
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public String getAsString(FacesContext facesContext, UIComponent uIComponent, Object value) {
		// TODO Auto-generated method stub
		try {
			return ((PosterminalProducer) value).getId().toString();
		} catch(Exception e) {
			// TODO MAKE LOGGING NOT WARNING
			System.out.println(value.toString());
			e.printStackTrace();
		}
		return null;
	}
	
}
